const http = require('http');

// 创建http服务
const server = http.createServer((req, res) => {
    const { method, url, headers: { host } } = req;

    console.log('\r\n------------method--------------\r\n');
    console.log(method);
    console.log('\r\n------------method--------------\r\n');

    const urlObj = new URL(url, `http://${host}`);
    console.log('\r\n------------urlObj--------------\r\n');
    console.log(urlObj);
    console.log('\r\n------------urlObj--------------\r\n');


    res.setHeader('content-type', 'text/plain;charset=utf-8');

    if (method === 'GET') {
        const { pathname } = urlObj
        if (pathname === '/login') {
            res.end('登录 ')
        } else if (pathname === '/register') {
            res.end('注册')
        } else {
            res.end('Not Found')
        }
    }

})

// 监听9000端口
server.listen(9000, () => {
    console.log('服务启动了');
})